package com.briup.demo.server;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.demo.bean.CmsStudent;
import com.briup.demo.mapper.CmsStudentMapper;

@Service
public class CmsStudentService {

	@Autowired
	private CmsStudentMapper studentMapper;
	
	public List<CmsStudent> findAll(){
		return studentMapper.selectAll();
	}
	
	public List<CmsStudent> findByName(String name) {
		return studentMapper.findByName(name);
	}
	
	public int deleteByNum(String num) {
		return studentMapper.deleteByPrimaryKey(num);
	}
	
	public int batchDelete(String[] nums) {
		if(nums!=null&&nums.length>0) {
			return studentMapper.batchDeleteByNums(nums);
		}
		return 0;
	}
	
	public void saveOrUpdate(CmsStudent student) {
		if(student.getNum()!= null) {
			studentMapper.updateByPrimaryKey(student);
		}else {
			student.setNum(UUID.randomUUID().toString());
			studentMapper.insert(student);
		}
	}

}